﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CrazyWorship1
{
    /// <summary>
    /// Interaction logic for SongSelectControl.xaml
    /// </summary>
    public partial class SongSelectControl : UserControl
    {
        AssetManager _assetManager;
        public static readonly RoutedEvent SongChangedEvent = EventManager.RegisterRoutedEvent(
      "SongChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SongSelectControl));

        public SongSelectControl()
        { InitializeComponent(); }
        public AssetManager AssetManager
        {
            get
            { return _assetManager; }
            set
            {
                _assetManager = value;
                this.DataContext = this;
            }
        }


        // Provide CLR accessors for the event
        public event RoutedEventHandler SongChanged
        {
            add { AddHandler(SongChangedEvent, value); }
            remove { RemoveHandler(SongChangedEvent, value); }
        }
        void RaiseSongChangedEvent()
        {
            RoutedEventArgs newEventArgs = new RoutedEventArgs(SongSelectControl.SongChangedEvent);
            RaiseEvent(newEventArgs);
        }

        public Song SelectedSongInfo
        {
            get
            { return ((Song)songs.SelectedItem); }
        }
        public Song GetSelectedSong()
        {
            if (SelectedSongInfo == null)
                return null;
            return SelectedSongInfo;
        }
        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            RaiseSongChangedEvent();
            //LOADSONG REMOTELY
            Song si = (Song)songs.SelectedItem;
            if (si == null)
                _assetManager.ClientsUnloadSong();
            else
                _assetManager.ClientsLoadSong(si);

        }
    }
}
